# PowerShell脚本：设置Docker MySQL环境配置
Write-Host "设置Docker MySQL环境配置..." -ForegroundColor Green

# 检查Docker是否运行
try {
    docker info | Out-Null
    Write-Host "✅ Docker正在运行" -ForegroundColor Green
} catch {
    Write-Host "❌ Docker未运行，请先启动Docker Desktop" -ForegroundColor Red
    exit 1
}

# 启动Docker容器
Write-Host "`n正在启动MySQL和phpMyAdmin容器..." -ForegroundColor Yellow
docker-compose up -d

# 等待容器启动
Write-Host "`n等待MySQL容器启动..." -ForegroundColor Yellow
Start-Sleep -Seconds 15

# 检查容器状态
Write-Host "`n检查容器状态：" -ForegroundColor Cyan
docker-compose ps

# 复制环境配置文件
$sourceFile = "env.docker"
$targetFile = ".env"

if (Test-Path $sourceFile) {
    Copy-Item $sourceFile $targetFile -Force
    Write-Host "`n✅ 已将Docker配置复制到 .env" -ForegroundColor Green
} else {
    Write-Host "`n❌ 源配置文件不存在: $sourceFile" -ForegroundColor Red
}

Write-Host "`n" + "="*50
Write-Host "Docker MySQL配置完成！" -ForegroundColor Green
Write-Host "="*50

Write-Host "`nMySQL数据库信息：" -ForegroundColor Cyan
Write-Host "  主机: localhost"
Write-Host "  端口: 3306"
Write-Host "  数据库: quantitative_advanced"
Write-Host "  用户名: quantitative_user"
Write-Host "  密码: quantitative_password"

Write-Host "`nphpMyAdmin管理界面：" -ForegroundColor Cyan
Write-Host "  URL: http://localhost:8080"
Write-Host "  用户名: root"
Write-Host "  密码: quantitative_password"

Write-Host "`n按任意键继续测试数据库连接..." -ForegroundColor Yellow
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")

# 测试数据库连接
Write-Host "`n开始测试数据库连接..." -ForegroundColor Green
python database/test_database.py
